//
//  customerViewController.m
//  HJB
//
//  Created by jiezsoft.com on 14-10-10.
//  Copyright (c) 2014年 jiezsoft.com. All rights reserved.
//

#import "orderLIstViewController.h"
#import "activityCell.h"
#import "HJBsingleton.h"
#import "UIViewExt.h"
#import "CycleScrollViews.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "InputHelper.h"
#import "huiyuandengjiViewController.h"
#import "UIImageView+WebCache.h"
#import "shouyingViewController.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "orderListCell.h"
#import "huiyuanDetailsViewController.h"
#import "OrederxiangqiangViewController.h"
#import "DaogouViewController.h"
#import "ShopcatListViewController.h"
#import "TheLoginViewController.h"
#import "AdvancedFilterListViewController.h"

@interface orderLIstViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UISearchBarDelegate,AdvancedFilterListViewControllerDelegate>
@property (strong, nonatomic) NSString *areaValue;
@property (strong, nonatomic) NSString*cityValue;


@end

@implementation orderLIstViewController

{
    UISearchBar *search;
    HJBsingleton* commdity;
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    NSMutableArray*DocNum;
    NSMutableArray*DocStatus;
    NSMutableArray*DocDate;
    NSMutableArray*DocTotal;
    NSMutableArray*ItemName;
    NSMutableArray*Number;
    NSMutableArray*GramTotal;
    NSMutableArray* GuideCode;
    NSMutableArray* GuideName;
    NSMutableArray* MemberCode;
    NSMutableArray* MemberName;
    NSMutableArray*DataLineFileterParam;
    NSString *result;
    int pageNumber;
    MBProgressHUD *progressHud;
    UIView* backview1;
    UIScrollView*myscrollView;
    NSString* sous;
    int pageNumber1;
    int pageNumber2;
    NSString*meiyousuos;
    UIView*view3;
    UITextField*searchTextField;
    UITextField*telTextFied;
    UITextField*zbsTextFied;
    UITextField*zbsTextFied1;
    UITextField*gjzFied;
    UITextField*Salary1;
    UITextField*WorkExper1;
    UIView *view1;
    UIView *view2;
    UIButton*btn;
    UIButton*btn1;
    UIButton*btn2;
    UIView*myToolBar1;
    UIButton* sxBtn;
    UIButton*jiazai;
    float lastContentOffset;
    UIButton*i22;
    UIButton*i1;
    UIButton*i12;
    
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
    self.navigationController.navigationBar.barStyle = UIStatusBarStyleDefault;
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"back.png"];
    CGRect backframe = CGRectMake(0,0,23/2,41/2);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    UIView* view=[[UIView alloc]initWithFrame:CGRectMake(10, 0, ScreenWidth*705/750, 65/2)];
    view.backgroundColor=zuiqianhuicolor;
    
    UIButton *sxBtn1 = [[UIButton alloc] initWithFrame:CGRectMake( 2, 4, 50/2, 50/2)];
    [sxBtn1 setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
    //[sxBtn addTarget:self action:@selector(sou) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:sxBtn1];
    
    
    searchTextField = [[UITextField alloc] initWithFrame:CGRectMake(sxBtn1.right,1, ScreenWidth*400/750,65/2)];
    [searchTextField setBorderStyle:   UITextBorderStyleNone]; //外框类型
    searchTextField.placeholder = @"  请输入订单号或日期"; //默认显示的字
    searchTextField.font = [UIFont systemFontOfSize: 14];
    searchTextField.tag=22;
    searchTextField.keyboardType = UIKeyboardTypeDecimalPad;
    searchTextField.returnKeyType = UIReturnKeyDone;
    searchTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    searchTextField.delegate = self;
    //[searchTextField addTarget:self action:@selector(userNumberLimitTextLength:) forControlEvents:UIControlEventEditingChanged];
    [view addSubview:searchTextField];
    self.navigationItem.titleView = view;
    
    commdity.huiyuanbudeng=@"";
    [self add];
    
    
    // 手势
    UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
    singleFingerOne.numberOfTouchesRequired = 1; //手指数
    singleFingerOne.numberOfTapsRequired = 1; //tap次数
    singleFingerOne.delegate = self;
    [myscrollView addGestureRecognizer:singleFingerOne];
    
    UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    searchTextField.inputAccessoryView = myToolBar;
    
    
    
}

-(void)OnTapDone{
    
    [searchTextField resignFirstResponder];
    
    [self add];
    
    
}



- (void)viewDidLoad
{
    
    [super viewDidLoad];
 
    [self addFooter];
    DataLineFileterParam=[[NSMutableArray alloc]init];
    
    
    
    
}
-(void)add{
    
    
    
    self.sat=nil;
    
    pageNumber = 1;
    pageNumber1= 1;
    
    MemberName= [[NSMutableArray alloc] init];
    MemberCode= [[NSMutableArray alloc] init];
    GuideName= [[NSMutableArray alloc] init];
    GuideCode= [[NSMutableArray alloc] init];
    GramTotal= [[NSMutableArray alloc] init];
    Number= [[NSMutableArray alloc] init];
    ItemName= [[NSMutableArray alloc] init];
    DocTotal = [[NSMutableArray alloc] init];
    DocDate = [[NSMutableArray alloc] init];
    DocNum = [[NSMutableArray alloc] init];
    DocStatus = [[NSMutableArray alloc] init];
    
    
    _table.delegate=self;
    _table.dataSource=self;
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    commdity=[HJBsingleton shared];
    
    meiyousuos=@"meiyou";
    sous=nil;
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"Token"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"Token"];
    [param setValue:@"1" forKey:@"PageIndex"];
    [param setValue:@"20" forKey:@"PageSize"];
    [param setValue:searchTextField.text forKey:@"KeyWord"];
    
    [param setValue:DataLineFileterParam forKey:@"DataLineFileterParam"];
    NSLog(@"====%@",param);
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"Guide/OrderList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                UIView*view11=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,168/2)];
                view1.backgroundColor=[UIColor whiteColor];
                UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,80/2)];
                view.backgroundColor= zuiqianhuicolor;
                [view11 addSubview:view];
                
                _table.tableHeaderView=view11;
                UILabel* duoshao=[[UILabel alloc]initWithFrame:CGRectMake(15,25/2, 200, 15)];
                duoshao.text=[NSString stringWithFormat:@"订单（共有 %@ 条记录）",[severDataDict.dataDict objectForKey:@"TotalCount"]];
                duoshao.textColor=zhonghuiColor;
                duoshao.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
                [view addSubview:duoshao];
                UIButton*dengjilabel1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*590/750,  15/2, ScreenWidth*140/750,50/2)];
                [dengjilabel1.layer setCornerRadius:2.0];
                [dengjilabel1.layer setBorderWidth:0.5];
                [dengjilabel1.layer setMasksToBounds:YES];
                [dengjilabel1 addTarget:self action:@selector(sx:) forControlEvents:UIControlEventTouchUpInside];
                CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
                CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){153/255.0,153/255.0, 153/255.0, 1.0   });
                [dengjilabel1.layer setBorderColor:colorref2];//边框颜色
                [dengjilabel1 setTitle:@"     筛选" forState:UIControlStateNormal];
                dengjilabel1.titleLabel.font=[UIFont systemFontOfSize:fourteenfotORthirteenfot];
//              [dengjilabel1 setTitleColor:shenhuicolor forState:UIControlStateNormal];
                dengjilabel1.titleLabel.textAlignment=NSTextAlignmentRight;
                [view addSubview:dengjilabel1];
                
                
                sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(3, 0, ScreenWidth*50/750, 50/2)];
//              [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
                [sxBtn addTarget:self action:@selector(sx:) forControlEvents:UIControlEventTouchUpInside];
                [dengjilabel1 addSubview:sxBtn];
                if (DataLineFileterParam.count>0) {
                    
                    [dengjilabel1 setTitleColor:huangtitleColor forState:UIControlStateNormal];
                    [sxBtn setImage:[UIImage imageNamed:@"yishaixuan"] forState:UIControlStateNormal];
                    
                
                }else{
                    [dengjilabel1 setTitleColor:shenhuicolor forState:UIControlStateNormal];
                    [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
                }

                NSString*GoldPrice=[NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"DocPriceTotal"]];
                NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                [numberFormatter setPositiveFormat:@"###,##0.00;"];
                NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];
                UILabel* duoshao1=[[UILabel alloc]initWithFrame:CGRectMake(15,108/2, ScreenWidth, 15)];
                duoshao1.text=[NSString stringWithFormat:@"共%@件/%@g 总金额¥ %@",[severDataDict.dataDict objectForKey:@"TotalCount"],[severDataDict.dataDict objectForKey:@"DocGramTotal"],formattedNumberString];
                duoshao1.textColor=zhonghuiColor;
                duoshao1.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
                [view11 addSubview:duoshao1];
                UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,167/2, ScreenWidth-30, 0.5)];
                _xianview.image=[UIImage imageNamed:@"_0001_zhangdanxiangqingxuxian.png"];
                [view11 addSubview:_xianview];

                
                for (NSDictionary* dicc in arrr )
                {
                    [DocNum addObject:[dicc valueForKey:@"DocNum"]];
                    [DocStatus addObject:[dicc valueForKey:@"DocStatus"]];
                    [DocDate addObject:[dicc valueForKey:@"DocDate"]];
                    [DocTotal addObject:[dicc valueForKey:@"DocTotal"]];
                    [ItemName addObject:[dicc valueForKey:@"ItemName"]];
                    [Number addObject:[dicc valueForKey:@"Number"]];
                    [GramTotal addObject:[dicc valueForKey:@"GramTotal"]];
                    [GuideCode addObject:[dicc valueForKey:@"GuideCode"]];
                    
                    [GuideName addObject:[dicc valueForKey:@"GuideName"]];
                    
                    [MemberCode addObject:[dicc valueForKey:@"MemberCode"]];
                    
                    [MemberName addObject:[dicc valueForKey:@"MemberName"]];
                    
                }
                [_table reloadData];
                
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    
                    TheLoginViewController * second =
                    [[TheLoginViewController alloc]
                     initWithNibName:@"TheLoginViewController"
                     bundle:nil];
                    //        second.textt =self.text.text;
                    //        //    second.label.text = @"正向";
                    [self presentViewController:second animated:YES completion:nil];
                    
                }
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
    
}




//上拉刷新
- (void)addFooter
{
    
   
    
    MJRefreshFooterView* footer = [MJRefreshFooterView footer];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        
        pageNumber++;
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"Token"];
        if (Token ==nil) {
            Token=@"dd";
        }
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setValue:Token forKey:@"Token"];
        
        [params setValue:searchTextField.text forKey:@"KeyWord"];
        [params setValue:[NSString stringWithFormat:@"%d" ,pageNumber] forKey:@"PageIndex"];
        [params setValue:@"20" forKey:@"PageSize"];
        [params setValue:DataLineFileterParam forKey:@"DataLineFileterParam"];
        NSLog(@"====%@",params);
        
        
        
        
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        [HttpRequest requestData:@"Guide/OrderList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    
                    NSMutableArray* arrr=[[NSMutableArray alloc]init];
                    
                    arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                    
                    
                    for (NSDictionary* dicc in arrr )
                    {
                        [DocNum addObject:[dicc valueForKey:@"DocNum"]];
                        [DocStatus addObject:[dicc valueForKey:@"DocStatus"]];
                        [DocDate addObject:[dicc valueForKey:@"DocDate"]];
                        [DocTotal addObject:[dicc valueForKey:@"DocTotal"]];
                        [ItemName addObject:[dicc valueForKey:@"ItemName"]];
                        [Number addObject:[dicc valueForKey:@"Number"]];
                        [GramTotal addObject:[dicc valueForKey:@"GramTotal"]];
                        [GuideCode addObject:[dicc valueForKey:@"GuideCode"]];
                        
                        [GuideName addObject:[dicc valueForKey:@"GuideName"]];
                        
                        [MemberCode addObject:[dicc valueForKey:@"MemberCode"]];
                        
                        [MemberName addObject:[dicc valueForKey:@"MemberName"]];
                        
                    }
                    [_table reloadData];
                    
                    
                    
                    
                }else{
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    // [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
                
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
            
        }];
        
        
        
    
    
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:1.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };

}
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    [_table reloadData];
    [refreshView endRefreshing];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [DocNum count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    orderListCell* cell = (orderListCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"orderListCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    UIButton*jiantou = [[UIButton alloc]init];
    jiantou.frame = CGRectMake(0,0, 8, 13);
    [jiantou setImage:[UIImage imageNamed:@"xiangzuo-.png"] forState:UIControlStateNormal];
    
    //    cell.accessoryView = jiantou;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSString *s21 = [NSString stringWithFormat:@"%@",  [DocNum objectAtIndex:indexPath.row]];
    UIFont *font21 = [UIFont systemFontOfSize:fifteenfotORfourteenfot];
    CGSize size21 = CGSizeMake(320, 2000);
    CGSize labelsize21 = [s21 sizeWithFont:font21 constrainedToSize:size21 lineBreakMode:NSLineBreakByCharWrapping];
    cell.DocNum.text =[NSString stringWithFormat:@"%@ ",  s21];
   
    cell.DocNum.textColor=[UIColor blackColor];
    cell.DocNum.frame=CGRectMake(30*ScreenWidth/750, ScreenHeight*40/1334, labelsize21.width,fifteenfotORfourteenfot);
    cell.DocNum.font= [UIFont fontWithName:@"Arial" size:fifteenfotORfourteenfot],
    cell.DocNumduosao=[DocNum objectAtIndex:indexPath.row];
    cell.sat=[DocStatus objectAtIndex:indexPath.row];
    
    
    NSString *s2 = [NSString stringWithFormat:@"【%@】",  [DocStatus objectAtIndex:indexPath.row]];
    UIFont *font2 = [UIFont systemFontOfSize:fourteenfotORthirteenfot];
    CGSize size2 = CGSizeMake(320, 2000);
    CGSize labelsize2 = [s2 sizeWithFont:font2 constrainedToSize:size2 lineBreakMode:NSLineBreakByCharWrapping];

    [cell.DocStatus.layer setCornerRadius:0];
    cell.DocStatus.frame=CGRectMake(cell.DocNum.right-6,  ScreenHeight*40/1334, labelsize2.width, fourteenfotORthirteenfot);
    cell.DocStatus.text=[NSString stringWithFormat:@"%@",  s2];
    cell.DocStatus.font=[UIFont systemFontOfSize:thirteenfotORtwelvefot];
    cell.DocStatus.textAlignment=NSTextAlignmentCenter;
    if ([[DocStatus objectAtIndex:indexPath.row] isEqualToString:@"未收银"]) {
         cell.DocStatus.textColor=titleColor;
    }if ([[DocStatus objectAtIndex:indexPath.row] isEqualToString:@"未发货"]) {
        cell.DocStatus.textColor=[UIColor colorWithRed:246/255.00 green:181/255.00 blue:0/255.00 alpha:1.0];;
    }
    if ([[DocStatus objectAtIndex:indexPath.row] isEqualToString:@"已发货"]) {
        cell.DocStatus.textColor=[UIColor colorWithRed:4/255.00 green:184/255.00 blue:149/255.00 alpha:1.0];;
    }
        if ([[DocStatus objectAtIndex:indexPath.row] isEqualToString:@"已结算"]) {
        cell.DocStatus.textColor=[UIColor colorWithRed:126/255.00 green:187/255.00 blue:35/255.00 alpha:1.0];
//        cell.DocStatus.textColor=[UIColor colorWithRed:255.00/255.00 green:255.00/255.00 blue:255.00/255.00 alpha:1.0];
    }
 
   
    
    
    
    
    NSString *s12 = [NSString stringWithFormat:@"%@", @"会员"];
    UIFont *font12 = [UIFont systemFontOfSize:fifteenfotORfourteenfot];
    CGSize size12 = CGSizeMake(320, 2000);
    CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
    cell.MemberCode.text=[NSString stringWithFormat:@"%@", @"会员"];
    cell.MemberCode.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
    cell.MemberCode.textColor=zhonghuiColor;
    cell.MemberCode.frame=CGRectMake(30*ScreenWidth/750,  ScreenHeight*105/1334,  labelsize12.width+3, fifteenfotORfourteenfot);
    
     cell.huiyuansat=[MemberName objectAtIndex:indexPath.row];
    if ([[MemberName objectAtIndex:indexPath.row] isEqualToString:@""]) {
        cell.MemberCode1.text=@"未填写";
    }else{
    cell.MemberCode1.text=[NSString stringWithFormat:@"%@", [MemberName objectAtIndex:indexPath.row]];
    }
    cell.MemberCode1.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
    cell.MemberCode1.textColor=shenhuicolor;
    cell.MemberCode1.frame=CGRectMake(cell.MemberCode.right,  ScreenHeight*105/1334,  100*ScreenWidth/750, fifteenfotORfourteenfot);
    
    cell.GuideCode.text=[NSString stringWithFormat:@"%@", @"导购"];
    cell.GuideCode.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
    cell.GuideCode.textColor=zhonghuiColor;
    cell.GuideCode.frame=CGRectMake(cell.MemberCode1.right+3,   ScreenHeight*105/1334, labelsize12.width+3, fifteenfotORfourteenfot);
    
    cell.GuideCode1.text=[NSString stringWithFormat:@"%@", [GuideName objectAtIndex:indexPath.row]];
    cell.GuideCode1.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
    cell.GuideCode1.textColor=shenhuicolor;
    cell.GuideCode1.frame=CGRectMake(cell.GuideCode.right,   ScreenHeight*105/1334,  450*ScreenWidth/750, fifteenfotORfourteenfot);
    
    
    
    
    
    cell.ItemName.text=[NSString stringWithFormat:@"%@", @"购买"];
    cell.ItemName.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
    cell.ItemName.textColor=zhonghuiColor;
    cell.ItemName.frame=CGRectMake(30*ScreenWidth/750,   ScreenHeight*142/1334,  labelsize12.width+3, fifteenfotORfourteenfot);
    cell.ItemName1.text=[NSString stringWithFormat:@"%@", [ItemName objectAtIndex:indexPath.row]];
    cell.ItemName1.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
    cell.ItemName1.textColor=shenhuicolor;
    cell.ItemName1.frame=CGRectMake(cell.ItemName.right,  ScreenHeight*142/1334, 300*ScreenWidth/750, fifteenfotORfourteenfot);
    
    
    cell.DocTotal.text=[NSString stringWithFormat:@"%@", @"金额"];
    cell.DocTotal.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
    cell.DocTotal.textColor=zhonghuiColor;
    cell.DocTotal.frame=CGRectMake(400*ScreenWidth/750,   ScreenHeight*142/1334,  labelsize12.width+3, fifteenfotORfourteenfot);
    NSString*GoldPrice=[NSString stringWithFormat:@"%@",[DocTotal objectAtIndex:indexPath.row]];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setPositiveFormat:@"###,##0.00;"];
    NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:GoldPrice.floatValue]];

    cell.DocTotal1.text=[NSString stringWithFormat:@"￥%@", formattedNumberString];
    cell.DocTotal1.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
    cell.DocTotal1.textColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    cell.DocTotal1.frame=CGRectMake(cell.DocTotal.right,  ScreenHeight*142/1334, 630*ScreenWidth/750, fifteenfotORfourteenfot);
    
    
    cell.DocDate.text=[NSString stringWithFormat:@"%@", [DocDate objectAtIndex:indexPath.row]];
    cell.DocDate.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
    cell.DocDate.textColor=zhonghuiColor;
    cell.DocDate.frame=CGRectMake(500*ScreenWidth/750,   ScreenHeight*50/1334,  230*ScreenWidth/750,fifteenfotORfourteenfot);
    cell.DocDate.textAlignment=NSTextAlignmentRight;
    
    cell.xuanxiang.frame=CGRectMake(ScreenWidth-40,   ScreenHeight*130/1334,  20,40);
    [cell.xuanxiang addTarget:self action:@selector(jiagemingxi1:) forControlEvents:UIControlEventTouchUpInside];
    [cell.xuanxiang setTitle:@"..." forState:UIControlStateNormal];
    [cell.xuanxiang setTitleColor:zhonghuiColor forState:UIControlStateNormal];
    
    
    
    cell.dianju.frame=CGRectMake(ScreenWidth-100,  0,  100,220*ScreenHeight/1334);
    [cell.dianju addTarget:self action:@selector(jiagemingxi1:) forControlEvents:UIControlEventTouchUpInside];
    if (DocNum.count !=indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 220*ScreenHeight/1334-0.35, ScreenWidth-30, 0.35)];
        lineLabel1.backgroundColor=[UIColor groupTableViewBackgroundColor];;
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    if (DocNum.count ==indexPath.row+1) {
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 220*ScreenHeight/1334-0.35, ScreenWidth, 0.35)];
        lineLabel1.backgroundColor=[UIColor groupTableViewBackgroundColor];
        [cell.contentView addSubview:lineLabel1];
        
    }
    
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return  220*ScreenHeight/1334;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    [i12 removeFromSuperview];
    [i22 removeFromSuperview];
    [i1 removeFromSuperview];
    
    commdity.DocNum=DocNum[indexPath.row];
    OrederxiangqiangViewController *detailViewController = [[OrederxiangqiangViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
    


}

-(void)jiagemingxi:(UIButton*)sender{
    [i12 removeFromSuperview];
    [i22 removeFromSuperview];
    [i1 removeFromSuperview];


}
-(void)jiagemingxi1:(UIButton*)sender{
    
    [i12 removeFromSuperview];
    [i22 removeFromSuperview];
    [i1 removeFromSuperview];
    
    UIButton* button=(UIButton * )sender;
    orderListCell* cell=(orderListCell* )button.superview.superview;
    commdity.DocNum=cell.DocNumduosao;
    
    if ([cell.sat isEqualToString:@"已结算"]) {
       
        
        
//        i22=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*330/750, 0, ScreenWidth*140/750, 220*ScreenHeight/1334)];
//        i22.backgroundColor=zuiqianhuicolor;
//        [i22 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        i22.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
//        [i22 addTarget:self action:@selector(bupiaoju:) forControlEvents:UIControlEventTouchUpInside];
//        [i22 setTitle:@"票据补打" forState:UIControlStateNormal];
//        [cell addSubview:i22];
        
if ([cell.huiyuansat isEqualToString:@""]) {
        
        i12=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*470/750, 0, ScreenWidth*140/750, 220*ScreenHeight/1334)];
        i12.backgroundColor=[UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:1.0];

        [i12 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        i12.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
        [i12 addTarget:self action:@selector(buhuiyuan:) forControlEvents:UIControlEventTouchUpInside];
        [i12 setTitle:@"会员补登" forState:UIControlStateNormal];
        [cell addSubview:i12];

         }else{
             i12=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*470/750, 0, ScreenWidth*140/750, 220*ScreenHeight/1334)];
             i12.backgroundColor=[UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:1.0];
             [i12 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
             i12.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
            [i12 addTarget:self action:@selector(buhuiyuan:) forControlEvents:UIControlEventTouchUpInside];
             [i12 setTitle:@"会员修改" forState:UIControlStateNormal];
             [cell addSubview:i12];
         
         }
        i1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*610/750, 0,ScreenWidth*140/750, 220*ScreenHeight/1334)];
        i1.backgroundColor=qianhuicolor;
        [i1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        i1.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
        [i1 addTarget:self action:@selector(qixiaoshouyin:) forControlEvents:UIControlEventTouchUpInside];
        [i1 setTitle:@"补收银" forState:UIControlStateNormal];
        [cell addSubview:i1];
        

   
    }
   
    
    if ([cell.sat isEqualToString:@"已取消"]) {
        
        
        
//        i22=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*330/750, 0, ScreenWidth*140/750, 220*ScreenHeight/1334)];
//        i22.backgroundColor=zuiqianhuicolor;
//        [i22 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        i22.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
//        [i22 addTarget:self action:@selector(bupiaoju:) forControlEvents:UIControlEventTouchUpInside];
//        [i22 setTitle:@"票据补打" forState:UIControlStateNormal];
//        [cell addSubview:i22];
//        i1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*470/750, 0,ScreenWidth*140/750, 220*ScreenHeight/1334)];
//        i1.backgroundColor=[UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:1.0];
//        [i1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        i1.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
//        [i1 addTarget:self action:@selector(bushouyin:) forControlEvents:UIControlEventTouchUpInside];
//        [i1 setTitle:@"补收银" forState:UIControlStateNormal];
//        [cell addSubview:i1];
//        
//        
//        if ([cell.huiyuansat isEqualToString:@""]) {
//            
//            i12=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*610/750, 0, ScreenWidth*140/750, 220*ScreenHeight/1334)];
//            i12.backgroundColor=qianhuicolor;
//            [i12 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//            i12.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
//            [i12 addTarget:self action:@selector(buhuiyuan:) forControlEvents:UIControlEventTouchUpInside];
//            [i12 setTitle:@"会员补登" forState:UIControlStateNormal];
//            [cell addSubview:i12];
//            
//        }else{
//            i12=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*610/750, 0, ScreenWidth*140/750, 220*ScreenHeight/1334)];
//            i12.backgroundColor=qianhuicolor;
//            [i12 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//            i12.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
//            [i12 addTarget:self action:@selector(buhuiyuan:) forControlEvents:UIControlEventTouchUpInside];
//            [i12 setTitle:@"会员修改" forState:UIControlStateNormal];
//            [cell addSubview:i12];
//            
//        }
        
    }
    
    
    
    if ([cell.sat isEqualToString:@"未收银"]) {
        
        
        
//        i22=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*330/750, 0, ScreenWidth*140/750, 220*ScreenHeight/1334)];
//        i22.backgroundColor=zuiqianhuicolor;
//        [i22 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        i22.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
//        [i22 addTarget:self action:@selector(bupiaoju:) forControlEvents:UIControlEventTouchUpInside];
//        [i22 setTitle:@"票据补打" forState:UIControlStateNormal];
//        [cell addSubview:i22];
        i1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*610/750, 0,ScreenWidth*140/750, 220*ScreenHeight/1334)];
        i1.backgroundColor=[UIColor colorWithRed:228/255.0 green:228/255.0 blue:228/255.0 alpha:1.0];
        [i1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        i1.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
        [i1 addTarget:self action:@selector(bushouyin:) forControlEvents:UIControlEventTouchUpInside];
        [i1 setTitle:@"补收银" forState:UIControlStateNormal];
        [cell addSubview:i1];
        
        
        if ([cell.huiyuansat isEqualToString:@""]) {
            
            i12=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*470/750, 0, ScreenWidth*140/750, 220*ScreenHeight/1334)];
            i12.backgroundColor=qianhuicolor;
            [i12 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            i12.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
            [i12 addTarget:self action:@selector(buhuiyuan:) forControlEvents:UIControlEventTouchUpInside];
            [i12 setTitle:@"会员补登" forState:UIControlStateNormal];
            [cell addSubview:i12];
            
        }else{
            i12=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*470/750, 0, ScreenWidth*140/750, 220*ScreenHeight/1334)];
            i12.backgroundColor=qianhuicolor;
            [i12 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            i12.titleLabel.font=[UIFont systemFontOfSize:fifteenfotORfourteenfot];
            [i12 addTarget:self action:@selector(buhuiyuan:) forControlEvents:UIControlEventTouchUpInside];
            [i12 setTitle:@"会员修改" forState:UIControlStateNormal];
            [cell addSubview:i12];
            
        }
        
    }


    
    
   
    
}


-(void)bupiaoju:(UIButton*)sender{
    [i12 removeFromSuperview];
    [i22 removeFromSuperview];
    [i1 removeFromSuperview];
    
    
    
    
    
}
-(void)bushouyin:(UIButton*)sender{
    [i12 removeFromSuperview];
    [i22 removeFromSuperview];
    [i1 removeFromSuperview];
    

    
    shouyingViewController *detailViewController = [[shouyingViewController alloc] init];
    
        commdity.shezhi=@"bushouyin";
        commdity.DocType=@"Order";
    
    NSLog(@"%@",commdity.DocNum);
    [self.navigationController pushViewController:detailViewController animated:YES];

}


-(void)qixiaoshouyin:(UIButton*)sender{
    [i12 removeFromSuperview];
    [i22 removeFromSuperview];
    [i1 removeFromSuperview];
//
//    
//    
//    shouyingViewController *detailViewController = [[shouyingViewController alloc] init];
//    
//    commdity.shezhi=@"qx";
//    commdity.DocType=@"Order";
//    
//    NSLog(@"%@",commdity.DocNum);
//    [self.navigationController pushViewController:detailViewController animated:YES];
    
}




-(void)buhuiyuan:(UIButton*)sender{
    [i12 removeFromSuperview];
    [i22 removeFromSuperview];
    [i1 removeFromSuperview];
    
    huiyuandengjiViewController *detailViewController = [[huiyuandengjiViewController alloc] init];
    commdity.addhuiyuanViewController=@"选择";
    commdity.huiyuanbudeng=@"budeng";
    NSLog(@"%@",commdity.DocNum);
    [self.navigationController pushViewController:detailViewController animated:YES];

    
    
}






-(void)sx:(UIButton*)sender{
    
    
    
    
    AdvancedFilterListViewController* store=[[AdvancedFilterListViewController alloc]init];
    store.delegate = self;
    commdity.FilterBusType=@"Order";
    [DataLineFileterParam removeAllObjects];
    [self.navigationController pushViewController:store animated:YES];
    
}
#pragma mark  筛选后回调

- (void)doSomethingAfterSelectDic:(NSDictionary *)dic{
    
    if (dic ==nil) {
        [DataLineFileterParam removeAllObjects];
    }else{
        
        NSString *FilterCode = [dic objectForKey:@"FilterCode"];
        NSString *FilterName = [dic objectForKey:@"FilterName"];
        NSString *FilterTypeCode = [dic objectForKey:@"FilterTypeCode"];
        NSString *FilterTypeName = [dic objectForKey:@"FilterTypeName"];
        
        NSLog(@"FilterCode:%@",FilterCode);
        NSLog(@"FilterName:%@",FilterName);
        NSLog(@"FilterTypeCode:%@",FilterTypeCode);
        NSLog(@"FilterTypeName:%@",FilterTypeName);
        
        for (int i=0; i<DataLineFileterParam.count; i++) {
            
            NSString *codeStr = [[DataLineFileterParam objectAtIndex:i]objectForKey:@"FilterTypeName"];
            if ([codeStr isEqualToString:FilterTypeName] ) {
                [DataLineFileterParam removeObjectAtIndex:i];//从指定索引移除
            }
        }
        [DataLineFileterParam addObject:dic];
        
    }
    
    NSLog(@"-----------FilterTypeName:%@",DataLineFileterParam);
    
    //    [self showAlertMessage:[NSString stringWithFormat:@"选择了%@,%@,单号%@",FilterTypeName,FilterName,FilterCode]];
}

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

////上拉刷新
//- (void)addheader
//{
//    MJRefreshHeaderView* footer = [MJRefreshHeaderView header];
//    footer.scrollView = _table;
//    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
//    {
//
//        //        [Global hideProgressHUDInternal:mainScroll];
//
//
//        //这里的RefreshView就是footer
//        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
//        //        NSLog(@"%@--->正在刷新", mainScroll.class);
//    };
//
//}

-(void)jiazai1{
    [jiazai removeFromSuperview];
    
    
}
-(void)closeKeyBoad
{
    
    [searchTextField resignFirstResponder];
    
    
}
@end
